/*
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * openFuyao is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

package utils

import (
	"reflect"
	"testing"
)

func TestFilter(t *testing.T) {
	type args struct {
		ori []string
		f   func(string) bool
	}
	tests := []struct {
		name    string
		args    args
		wantRes []string
	}{
		// TODO: Add test cases.
		{
			name: "test1",
			args: args{
				ori: []string{"a", "b", "c"},
				f:   func(s string) bool { return s == "a" },
			},
			wantRes: []string{"a"},
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if gotRes := Filter(tt.args.ori, tt.args.f); !reflect.DeepEqual(gotRes, tt.wantRes) {
				t.Errorf("Filter() = %v, want %v", gotRes, tt.wantRes)
			}
		})
	}
}

func TestMap(t *testing.T) {
	type args struct {
		ori []string
		f   func(string) string
	}
	tests := []struct {
		name    string
		args    args
		wantRes []string
	}{
		// TODO: Add test cases.
		{
			name: "test1",
			args: args{
				ori: []string{"a", "b", "c"},
				f: func(s string) string {
					return s + "1"
				},
			},
			wantRes: []string{"a1", "b1", "c1"},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if gotRes := Map(tt.args.ori, tt.args.f); !reflect.DeepEqual(gotRes, tt.wantRes) {
				t.Errorf("Map() = %v, want %v", gotRes, tt.wantRes)
			}
		})
	}
}

func TestMapInPlace(t *testing.T) {
	type args struct {
		ori []string
		f   func(*string)
	}
	tests := []struct {
		name string
		args args
	}{
		// TODO: Add test cases.
		{
			name: "test1",
			args: args{
				ori: []string{"a", "b", "c"},
				f: func(s *string) {
					*s = *s + "1"
				},
			},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			MapInPlace(tt.args.ori, tt.args.f)
		})
	}
}

func TestReduce(t *testing.T) {
	type args struct {
		ori  []string
		f    func(string, string) string
		init string
	}
	tests := []struct {
		name    string
		args    args
		wantRes string
	}{
		// TODO: Add test cases.
		{
			name: "test1",
			args: args{
				ori:  []string{"a", "b", "c"},
				f:    func(a, b string) string { return a + b },
				init: "",
			},
			wantRes: "abc",
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if gotRes := Reduce(tt.args.ori, tt.args.f, tt.args.init); !reflect.DeepEqual(gotRes, tt.wantRes) {
				t.Errorf("Reduce() = %v, want %v", gotRes, tt.wantRes)
			}
		})
	}
}
